#include "items.h"

#include "parsers.h"

using namespace fortress;

items::items()
{
	walkable=false;
	canCarry=false;
}

items::~items()
{
	
}

items::items(items const & copy)
{
	convertItem(copy);
}

items & items::operator=(items const & copy)
{
	convertItem(copy);
	return *this;
}

void items::convertItem(items const &itemData)
{
	name.assign(itemData.name);
	singular.assign(itemData.singular);
	plural.assign(itemData.plural);
	cost = (itemData.cost);
	weight = (itemData.weight);
	walkable = (itemData.walkable);	// These two toggles could cause problems
	canCarry = (itemData.canCarry);	//
	transparent = (itemData.transparent);
	baseDamage = (itemData.baseDamage);
	color = (itemData.color);
	
	setGlyph(itemData.getGlyph());
	setColor(itemData.getColor());
}

itemFactory::itemFactory()
{
	parser = new TCODParser;
}

itemFactory::~itemFactory()
{
	delete parser;
}

std::map<int,items*> * itemFactory::readFile(char * filename)
{
	TCODParserStruct *itemStruct = parser->newStructure("item");
	itemStruct->addFlag("canCarry");
	itemStruct->addFlag("walkable");
	itemStruct->addProperty("singular",TCOD_TYPE_STRING,true);
	itemStruct->addProperty("plural",TCOD_TYPE_STRING,true);
	itemStruct->addProperty("weight",TCOD_TYPE_FLOAT,true);
	itemStruct->addProperty("cost",TCOD_TYPE_INT,true);
	itemStruct->addProperty("baseDamage",TCOD_TYPE_DICE,true);
	itemStruct->addProperty("color",TCOD_TYPE_COLOR,true);
	itemStruct->addProperty("glyph",TCOD_TYPE_CHAR,true);
	parseListen *parseObject = new parseListen();	// Make sure we're getting the memory copied
	parser->run(filename, parseObject);

	return parseObject->getItems();
}